/*
 * Copyright kingbi. 
 * Creator: mouzb
 */
package com.kingbi.util.xml;

import javax.xml.namespace.NamespaceContext;
import javax.xml.namespace.QName;
import javax.xml.xpath.XPath;
import javax.xml.xpath.XPathExpression;
import javax.xml.xpath.XPathExpressionException;
import javax.xml.xpath.XPathFactory;


/**
 * @author mouzb
 *
 */
public class XMLUtils {
	public static Object findNodeByXPath(Object src,String xp,QName returnType,NamespaceContext nsctxt){
		try {
			XPathFactory factory = XPathFactory.newInstance();
		    XPath xpath = factory.newXPath();
		    xpath.setNamespaceContext(nsctxt);
		    XPathExpression expr= xpath.compile(xp);
		    Object result = expr.evaluate(src, returnType);
		    return result;
		} catch (XPathExpressionException e) {
			e.printStackTrace();
		}
		return null;
	}
}
